package com.portal.sso.jdbc.service;

import com.portal.sso.core.server.PasswordEncodeServer;
import com.portal.sso.core.server.PortalUserServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate;


/**
 * @program: portal-sso
 * @description: jdbc数据库控制服务
 * @author: xuduo
 * @create: 2021-04-27 19:47
 * @Version: 1.0
 **/
@Configuration
@ConditionalOnClass(JdbcTemplate.class)
@EnableConfigurationProperties({PortalSsoJdbcProperties.class})
public class PortalSsoJdbcAutoConfiguration {
    @Autowired
    JdbcTemplate jdbcTemplate;
    @Autowired
    PortalSsoJdbcProperties portalSsoJdbcProperties;
    @Autowired
    PasswordEncodeServer passwordEncodeServer;
    @Bean
    @ConditionalOnMissingBean(PortalUserServer.class)
    @ConditionalOnClass(PortalUserServer.class)
//    @Primary
    public PortalUserServer portalSsoJdbcServer(){
        PortalUserServer portalSsoJdbcServer = new PortalSsoJdbcServer(jdbcTemplate,portalSsoJdbcProperties,passwordEncodeServer);
        return portalSsoJdbcServer;
    }
}
